<template>
  <i class="isvg-icon" v-if="svg" v-html="svg" :style="{ ...style, color, fontSize: size + 'px' }"></i>
  <svg v-if="name" :class="svgClass" v-bind="$attrs"
    :style="{ ...style, color, width: size + 'px', height: size + 'px' }">
    <use :xlink:href="iconName" />
  </svg>
</template>

<script setup>
import { computed, defineProps } from "vue";
const props = defineProps({
  svg: {
    type: String,
    default: "",
  },
  name: {
    type: String,
    required: true,
  },
  style: {
    type: Object,
    default: {},
  },
  color: {
    type: String,
    default: "",
  },
  size: {
    type: Number,
    // default: 12,
  },
});
const iconName = computed(() => `#${props.name}`);
const svgClass = computed(() => {
  if (props.name) return `svg-icon icon-${props.name}`;
  return "svg-icon";
});
</script>

<style scoped>
.isvg-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1em;
  height: 1em;
}

.svg-icon {
  width: 1em;
  height: 1em;
  fill: currentColor;
  vertical-align: bottom;
  /* vertical-align: middle; */
}
</style>
